import random

def math_quiz():
    score = 0
    questions = 5

    print("欢迎来到数学小测验!")
    print("你将回答 5 个简单的加减法问题.")

    for _ in range(questions):
        a = random.randint(1, 10)
        b = random.randint(1, 10)
        operation = random.choice(["+", "-"])
        correct_answer = eval(f"{a} {operation} {b}")

        user_answer = input(f"{a} {operation} {b} = ? ")

        if user_answer.isdigit() and int(user_answer) == correct_answer:
            score += 1
            print("回答正确!")
        else:
            print(f"错误! 正确答案是 {correct_answer}.")

    print(f"你的总得分是: {score}/{questions}.")

if __name__ == "__main__":
    math_quiz()
